package Front_end;
import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.scene.control.Label;
import javafx.scene.text.*;
import Back_end.*;
import javafx.scene.control.TextArea;
import javafx.event.EventHandler;
import javafx.event.ActionEvent;
import javafx.scene.control.TableView;
import javafx.scene.control.TableColumn;
import java.util.LinkedList;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.collections.FXCollections;
public class Window extends Application {

        static BookManager manager = new BookManager();
    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("Book Information Management System");
        // create a gridpane

        Scene menuscene = new Scene(menuButton(primaryStage),500,300);
        primaryStage.setScene(menuscene);
        primaryStage.show();
    }
    public static GridPane Add(Stage primaryStage) {
        // create a gridpane
        GridPane gridpane = new GridPane();

        // create the add button
        Button addButton = new Button("Add");
        Button retButton = new Button("Return");
        addButton.setPrefSize(100, 50);
        addButton.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        retButton.setPrefSize(100,50);
        retButton.setFont(Font.font("Arial",FontWeight.NORMAL,16));

        // set the button constraints
        GridPane.setConstraints(addButton, 0, 7);
        GridPane.setHalignment(addButton, HPos.CENTER);
        GridPane.setConstraints(retButton,1,7);
        GridPane.setHalignment(retButton,HPos.RIGHT);

        // create the labels for the information fields
        Label loginIDLabel = new Label("Login ID:");
        Label nameLabel = new Label("Name:");
        Label authorLabel = new Label("Author:");
        Label classCodeLabel = new Label("Class Code:");
        Label publicationUnitLabel = new Label("Publication Unit:");
        Label publicationTimeLabel = new Label("Publication Time:");
        Label priceLabel = new Label("Price:");

        // set the label font and alignment
        loginIDLabel.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        nameLabel.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        authorLabel.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        classCodeLabel.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        publicationUnitLabel.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        publicationTimeLabel.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        priceLabel.setFont(Font.font("Arial", FontWeight.NORMAL, 16));

        loginIDLabel.setAlignment(Pos.CENTER_RIGHT);
        nameLabel.setAlignment(Pos.CENTER_RIGHT);
        authorLabel.setAlignment(Pos.CENTER_RIGHT);
        classCodeLabel.setAlignment(Pos.CENTER_RIGHT);
        publicationUnitLabel.setAlignment(Pos.CENTER_RIGHT);
        publicationTimeLabel.setAlignment(Pos.CENTER_RIGHT);
        priceLabel.setAlignment(Pos.CENTER_RIGHT);

        // set the label constraints
        GridPane.setConstraints(loginIDLabel, 0, 0);
        GridPane.setConstraints(nameLabel, 0, 1);
        GridPane.setConstraints(authorLabel, 0, 2);
        GridPane.setConstraints(classCodeLabel, 0, 3);
        GridPane.setConstraints(publicationUnitLabel, 0, 4);
        GridPane.setConstraints(publicationTimeLabel, 0, 5);
        GridPane.setConstraints(priceLabel, 0, 6);

        TextField loginIDField = new TextField();
        TextField nameField = new TextField();
        TextField authorField = new TextField();
        TextField classCodeField = new TextField();
        TextField publicationUnitField = new TextField();
        TextField publicationTimeField = new TextField();
        TextField priceField = new TextField();

        loginIDField.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        nameField.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        authorField.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        classCodeField.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        publicationUnitField.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        publicationTimeField.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        priceField.setFont(Font.font("Arial", FontWeight.NORMAL, 16));

        loginIDField.setAlignment(Pos.CENTER_LEFT);
        nameField.setAlignment(Pos.CENTER_LEFT);
        authorField.setAlignment(Pos.CENTER_LEFT);
        classCodeField.setAlignment(Pos.CENTER_LEFT);
        publicationUnitField.setAlignment(Pos.CENTER_LEFT);
        publicationTimeField.setAlignment(Pos.CENTER_LEFT);
        priceField.setAlignment(Pos.CENTER_LEFT);

        // set the text field constraints
        GridPane.setConstraints(loginIDField, 1, 0); // column=1 row=0
        GridPane.setConstraints(nameField, 1, 1); // column=1 row=1
        GridPane.setConstraints(authorField, 1, 2); // column=1 row=2
        GridPane.setConstraints(classCodeField, 1, 3); // column=1 row=3
        GridPane.setConstraints(publicationUnitField, 1, 4); // column=1 row=4
        GridPane.setConstraints(publicationTimeField, 1, 5); // column=1 row=5
        GridPane.setConstraints(priceField, 1, 6); // column=1 row=6

        // add the event handler for the add button
        addButton.setOnAction(event -> {
            // get the values from the text fields
            String loginID = loginIDField.getText();
            String name = nameField.getText();
            String author = authorField.getText();
            String classCode = classCodeField.getText();
            String publicationUnit = publicationUnitField.getText();
            String publicationTime = publicationTimeField.getText();
            int price = Integer.parseInt(priceField.getText());

            // create a new book object with the values
            Book book = new Book(loginID, name, author, classCode, publicationUnit, publicationTime, price);

            // add the book object to the list
            manager.add(book);

            // clear the text fields
            loginIDField.clear();
            nameField.clear();
            authorField.clear();
            classCodeField.clear();
            publicationUnitField.clear();
            publicationTimeField.clear();
            priceField.clear();
        });
        retButton.setOnAction(event ->
                primaryStage.setScene(new Scene(menuButton(primaryStage),500,300)));
        // add the nodes to the gridpane
        gridpane.getChildren().addAll(loginIDLabel, nameLabel, authorLabel, classCodeLabel, publicationUnitLabel, publicationTimeLabel, priceLabel, loginIDField, nameField, authorField, classCodeField, publicationUnitField, publicationTimeField, priceField, addButton,retButton);

        // set the gridpane style
        gridpane.setStyle("-fx-background-color: lightblue;");

        return gridpane;
    }
    public static GridPane menuButton(Stage primaryStage)
    {
        GridPane gridpane = new GridPane();

// set the title label
        Label title = new Label("Book Information Management System");
        title.setFont(Font.font("Arial", FontWeight.BOLD, 24));
        GridPane.setConstraints(title, 0, 0, 5, 1);
        GridPane.setHalignment(title, HPos.CENTER); // align the title to the center

        Button addButton = new Button("Add");
        Button searchButton = new Button("Search");
        Button deleteButton = new Button("Delete");
        Button showButton = new Button("Show");
        Button updateButton = new Button("Update");
        Button exitButton = new Button("Exit");

// set the button size and font
        addButton.setPrefSize(200, 100);
        searchButton.setPrefSize(200, 100);
        deleteButton.setPrefSize(200, 100);
        showButton.setPrefSize(200, 100);
        exitButton.setPrefSize(200, 100);
        updateButton.setPrefSize(200,100);

        addButton.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        searchButton.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        deleteButton.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        showButton.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        exitButton.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
        updateButton.setFont(Font.font("Arial", FontWeight.NORMAL, 16));

// set the button constraints
        GridPane.setConstraints(addButton, 0, 1);
        GridPane.setConstraints(searchButton, 1, 1);
        GridPane.setConstraints(deleteButton, 0, 2);
        GridPane.setConstraints(showButton, 1, 2);
        GridPane.setConstraints(exitButton,1 , 3);
        GridPane.setConstraints(updateButton,0,3);

        gridpane.getChildren().addAll(title, addButton, searchButton, deleteButton, showButton, exitButton,updateButton);

        gridpane.setPadding(new Insets(10));
        gridpane.setHgap(10);
        gridpane.setVgap(10);


        gridpane.setStyle("-fx-background-color: lightblue;");
// set action of button
        addButton.setOnAction(event -> {
            primaryStage.setScene(new Scene(Add(primaryStage),500,300));
        });
        showButton.setOnAction(event -> {
            primaryStage.setScene(new Scene(ShowButton(primaryStage),500,300));
                }
        );
        exitButton.setOnAction(event -> {
            primaryStage.close();
        });
        searchButton.setOnAction(
                event -> primaryStage.setScene(new Scene(SearchButton(primaryStage),500,300))
        );
        deleteButton.setOnAction(
                event -> primaryStage.setScene(new Scene(DeleteButton(primaryStage),500,300))
        );
        updateButton.setOnAction((
                event -> primaryStage.setScene(new Scene(updateButton(primaryStage),500,300)))
                );
        return gridpane;
    }
    public static GridPane ShowButton(Stage primaryStage){
            GridPane gridPane = new GridPane();
            LinkedList<Book> books = manager.show();
            Button retButton = new Button("Return");

            //set event
            retButton.setOnAction(event ->
                    primaryStage.setScene(new Scene(menuButton(primaryStage)))
            );
            //文本域版本
            // create a text area to display the books
            /*TextArea bookArea = new TextArea();
            bookArea.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
            bookArea.setEditable(false); // make the text area read-only
            // append each book's information to the text area
            for (Book book : books) {
                bookArea.appendText(book.toString() + "\n");
            }
            gridPane.add(bookArea,0,0);*/
        //表格版本
        TableView<Book> bookTable = new TableView<>();
        // create the columns for the table view
        TableColumn<Book, String> loginIDColumn = new TableColumn<>("Login ID");
        TableColumn<Book, String> nameColumn = new TableColumn<>("Name");
        TableColumn<Book, String> authorColumn = new TableColumn<>("Author");
        TableColumn<Book, String> classCodeColumn = new TableColumn<>("Class Code");
        TableColumn<Book, String> publicationUnitColumn = new TableColumn<>("Publication Unit");
        TableColumn<Book, String> publicationTimeColumn = new TableColumn<>("Publication Time");
        TableColumn<Book, Integer> priceColumn = new TableColumn<>("Price");
        // set the cell value factory for each column
        loginIDColumn.setCellValueFactory(new PropertyValueFactory<>("loginID"));
        nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
        authorColumn.setCellValueFactory(new PropertyValueFactory<>("author"));
        classCodeColumn.setCellValueFactory(new PropertyValueFactory<>("classCode"));
        publicationUnitColumn.setCellValueFactory(new PropertyValueFactory<>("publicationUnit"));
        publicationTimeColumn.setCellValueFactory(new PropertyValueFactory<>("publicationTime"));
        priceColumn.setCellValueFactory(new PropertyValueFactory<>("price"));
        // add the columns to the table view
        bookTable.getColumns().addAll(loginIDColumn,
                nameColumn,
                authorColumn,
                classCodeColumn,
                publicationUnitColumn,
                publicationTimeColumn,
                priceColumn);
        bookTable.setItems(FXCollections.observableList(books));
        //set the retButton
        GridPane.setConstraints(retButton,0,1);
        GridPane.setHalignment(retButton,HPos.RIGHT);

        gridPane.add(bookTable,0,0);
        gridPane.add(retButton,0,1);
            gridPane.setStyle("-fx-background-color: lightblue;");

            return gridPane;
        }
        public static GridPane SearchButton(Stage primaryStage){
        GridPane gridPane = new GridPane();
        TextField forSearch = new TextField();
        Label tips = new Label("输入想要搜索的书（tips:请以书名或作者名为索引）");
        Button retButton = new Button("Return");
            retButton.setOnAction(event ->
                    primaryStage.setScene(new Scene(menuButton(primaryStage)))
            );
        //set for textfield
        forSearch.setEditable(true);
            TableView<Book> bookTable = new TableView<>();
            // create the columns for the table view
            TableColumn<Book, String> loginIDColumn = new TableColumn<>("Login ID");
            TableColumn<Book, String> nameColumn = new TableColumn<>("Name");
            TableColumn<Book, String> authorColumn = new TableColumn<>("Author");
            TableColumn<Book, String> classCodeColumn = new TableColumn<>("Class Code");
            TableColumn<Book, String> publicationUnitColumn = new TableColumn<>("Publication Unit");
            TableColumn<Book, String> publicationTimeColumn = new TableColumn<>("Publication Time");
            TableColumn<Book, Integer> priceColumn = new TableColumn<>("Price");
            // set the cell value factory for each column
            loginIDColumn.setCellValueFactory(new PropertyValueFactory<>("loginID"));
            nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
            authorColumn.setCellValueFactory(new PropertyValueFactory<>("author"));
            classCodeColumn.setCellValueFactory(new PropertyValueFactory<>("classCode"));
            publicationUnitColumn.setCellValueFactory(new PropertyValueFactory<>("publicationUnit"));
            publicationTimeColumn.setCellValueFactory(new PropertyValueFactory<>("publicationTime"));
            priceColumn.setCellValueFactory(new PropertyValueFactory<>("price"));
            // add the columns to the table view
            bookTable.getColumns().addAll(loginIDColumn,
                    nameColumn,
                    authorColumn,
                    classCodeColumn,
                    publicationUnitColumn,
                    publicationTimeColumn,
                    priceColumn);
            forSearch.setOnAction(event -> {
                String search = forSearch.getText();
                LinkedList<Book> books = manager.search(search);
                bookTable.setItems(FXCollections.observableList(books));
            });

            GridPane.setConstraints(retButton,0,3);
            GridPane.setHalignment(retButton,HPos.RIGHT);

            gridPane.setStyle("-fx-background-color: lightblue;");
            gridPane.add(tips,0,0);
            gridPane.add(forSearch,0,1);
            gridPane.add(bookTable,0,2);
            gridPane.add(retButton,0,3);
            return gridPane;
        }
    public static GridPane DeleteButton(Stage primaryStage){
        GridPane gridPane = new GridPane();
        TextField forSearch = new TextField();
        LinkedList<Book> books = manager.show();
        Label tips = new Label("输入想要删除的书所对应的LoginID");
        Button retButton = new Button("Return");
        retButton.setOnAction(event ->
                primaryStage.setScene(new Scene(menuButton(primaryStage)))
        );
        //set for textfield
        forSearch.setEditable(true);
        TableView<Book> bookTable = new TableView<>();
        // create the columns for the table view
        TableColumn<Book, String> loginIDColumn = new TableColumn<>("Login ID");
        TableColumn<Book, String> nameColumn = new TableColumn<>("Name");
        TableColumn<Book, String> authorColumn = new TableColumn<>("Author");
        TableColumn<Book, String> classCodeColumn = new TableColumn<>("Class Code");
        TableColumn<Book, String> publicationUnitColumn = new TableColumn<>("Publication Unit");
        TableColumn<Book, String> publicationTimeColumn = new TableColumn<>("Publication Time");
        TableColumn<Book, Integer> priceColumn = new TableColumn<>("Price");
        // set the cell value factory for each column
        loginIDColumn.setCellValueFactory(new PropertyValueFactory<>("loginID"));
        nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
        authorColumn.setCellValueFactory(new PropertyValueFactory<>("author"));
        classCodeColumn.setCellValueFactory(new PropertyValueFactory<>("classCode"));
        publicationUnitColumn.setCellValueFactory(new PropertyValueFactory<>("publicationUnit"));
        publicationTimeColumn.setCellValueFactory(new PropertyValueFactory<>("publicationTime"));
        priceColumn.setCellValueFactory(new PropertyValueFactory<>("price"));
        // add the columns to the table view
        bookTable.getColumns().addAll(loginIDColumn,
                nameColumn,
                authorColumn,
                classCodeColumn,
                publicationUnitColumn,
                publicationTimeColumn,
                priceColumn);
        bookTable.setItems(FXCollections.observableList(books));
        forSearch.setOnAction(event -> {
            String delete = forSearch.getText();
            if (delete != null) {
                manager.delete(delete);
                LinkedList<Book> newbooks = manager.show();
                bookTable.setItems(FXCollections.observableList(newbooks));
            }
        });
        // set the items for the table view
        //set the retButton
        GridPane.setConstraints(retButton,0,3);
        GridPane.setHalignment(retButton,HPos.RIGHT);

        gridPane.setStyle("-fx-background-color: lightblue;");
        gridPane.add(tips,0,0);
        gridPane.add(forSearch,0,1);
        gridPane.add(bookTable,0,2);
        gridPane.add(retButton,0,3);
        return gridPane;
    }
        public static GridPane updateButton(Stage primaryStage){
            GridPane gridpane = new GridPane();
            Label tips1 = new Label("请输入想要修改的书的LoginID");
            Label tips2 = new Label();
            TextField change = new TextField();
            LinkedList<Book> books = manager.show();
            change.setEditable(true);
            Button retButton  = new Button("Return");
            retButton.setOnAction(event ->
                    primaryStage.setScene(new Scene(menuButton(primaryStage)))
            );

            //表格版本
            TableView<Book> bookTable = new TableView<>();
            // create the columns for the table view
            TableColumn<Book, String> loginIDColumn = new TableColumn<>("Login ID");
            TableColumn<Book, String> nameColumn = new TableColumn<>("Name");
            TableColumn<Book, String> authorColumn = new TableColumn<>("Author");
            TableColumn<Book, String> classCodeColumn = new TableColumn<>("Class Code");
            TableColumn<Book, String> publicationUnitColumn = new TableColumn<>("Publication Unit");
            TableColumn<Book, String> publicationTimeColumn = new TableColumn<>("Publication Time");
            TableColumn<Book, Integer> priceColumn = new TableColumn<>("Price");
            // set the cell value factory for each column
            loginIDColumn.setCellValueFactory(new PropertyValueFactory<>("loginID"));
            nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
            authorColumn.setCellValueFactory(new PropertyValueFactory<>("author"));
            classCodeColumn.setCellValueFactory(new PropertyValueFactory<>("classCode"));
            publicationUnitColumn.setCellValueFactory(new PropertyValueFactory<>("publicationUnit"));
            publicationTimeColumn.setCellValueFactory(new PropertyValueFactory<>("publicationTime"));
            priceColumn.setCellValueFactory(new PropertyValueFactory<>("price"));
            // add the columns to the table view
            bookTable.getColumns().addAll(loginIDColumn,
                    nameColumn,
                    authorColumn,
                    classCodeColumn,
                    publicationUnitColumn,
                    publicationTimeColumn,
                    priceColumn);
            // set the items for the table view
            bookTable.setItems(FXCollections.observableList(books));
            gridpane.add(tips1,0,0);
            gridpane.add(change,0,1);
            gridpane.add(bookTable,0,2);
            gridpane.add(tips2,0,3);
            gridpane.add(retButton,0,4);
            GridPane.setHalignment(retButton,HPos.RIGHT);
            //set the change textField
            change.setOnAction(
                    event -> {
                        if(manager.judge(change.getText()))
                            primaryStage.setScene(new Scene(updateButton2(primaryStage)));
                    }
            );
            return gridpane;
        }
        public static GridPane updateButton2(Stage primaryStage){
        GridPane gridPane = new GridPane();
            // create the add button
            Button updateButton = new Button("Update");
            Button retButton = new Button("Return");
            updateButton.setPrefSize(100, 50);
            updateButton.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
            retButton.setPrefSize(100,50);
            retButton.setFont(Font.font("Arial",FontWeight.NORMAL,16));

            // set the button constraints
            GridPane.setConstraints(updateButton, 0, 7);
            GridPane.setHalignment(updateButton, HPos.CENTER);
            GridPane.setConstraints(retButton,1,7);
            GridPane.setHalignment(retButton,HPos.RIGHT);

            // create the labels for the information fields
            Label loginIDLabel = new Label("Login ID:");
            Label nameLabel = new Label("Name:");
            Label authorLabel = new Label("Author:");
            Label classCodeLabel = new Label("Class Code:");
            Label publicationUnitLabel = new Label("Publication Unit:");
            Label publicationTimeLabel = new Label("Publication Time:");
            Label priceLabel = new Label("Price:");

            // set the label font and alignment
            loginIDLabel.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
            nameLabel.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
            authorLabel.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
            classCodeLabel.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
            publicationUnitLabel.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
            publicationTimeLabel.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
            priceLabel.setFont(Font.font("Arial", FontWeight.NORMAL, 16));

            loginIDLabel.setAlignment(Pos.CENTER_RIGHT);
            nameLabel.setAlignment(Pos.CENTER_RIGHT);
            authorLabel.setAlignment(Pos.CENTER_RIGHT);
            classCodeLabel.setAlignment(Pos.CENTER_RIGHT);
            publicationUnitLabel.setAlignment(Pos.CENTER_RIGHT);
            publicationTimeLabel.setAlignment(Pos.CENTER_RIGHT);
            priceLabel.setAlignment(Pos.CENTER_RIGHT);

            // set the label constraints
            GridPane.setConstraints(loginIDLabel, 0, 0);
            GridPane.setConstraints(nameLabel, 0, 1);
            GridPane.setConstraints(authorLabel, 0, 2);
            GridPane.setConstraints(classCodeLabel, 0, 3);
            GridPane.setConstraints(publicationUnitLabel, 0, 4);
            GridPane.setConstraints(publicationTimeLabel, 0, 5);
            GridPane.setConstraints(priceLabel, 0, 6);

            TextField loginIDField = new TextField();
            TextField nameField = new TextField();
            TextField authorField = new TextField();
            TextField classCodeField = new TextField();
            TextField publicationUnitField = new TextField();
            TextField publicationTimeField = new TextField();
            TextField priceField = new TextField();

            loginIDField.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
            nameField.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
            authorField.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
            classCodeField.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
            publicationUnitField.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
            publicationTimeField.setFont(Font.font("Arial", FontWeight.NORMAL, 16));
            priceField.setFont(Font.font("Arial", FontWeight.NORMAL, 16));

            loginIDField.setAlignment(Pos.CENTER_LEFT);
            nameField.setAlignment(Pos.CENTER_LEFT);
            authorField.setAlignment(Pos.CENTER_LEFT);
            classCodeField.setAlignment(Pos.CENTER_LEFT);
            publicationUnitField.setAlignment(Pos.CENTER_LEFT);
            publicationTimeField.setAlignment(Pos.CENTER_LEFT);
            priceField.setAlignment(Pos.CENTER_LEFT);

            // set the text field constraints
            GridPane.setConstraints(loginIDField, 1, 0); // column=1 row=0
            GridPane.setConstraints(nameField, 1, 1); // column=1 row=1
            GridPane.setConstraints(authorField, 1, 2); // column=1 row=2
            GridPane.setConstraints(classCodeField, 1, 3); // column=1 row=3
            GridPane.setConstraints(publicationUnitField, 1, 4); // column=1 row=4
            GridPane.setConstraints(publicationTimeField, 1, 5); // column=1 row=5
            GridPane.setConstraints(priceField, 1, 6); // column=1 row=6

            // add the event handler for the add button
            updateButton.setOnAction(event -> {
                // get the values from the text fields
                String loginID = loginIDField.getText();
                String name = nameField.getText();
                String author = authorField.getText();
                String classCode = classCodeField.getText();
                String publicationUnit = publicationUnitField.getText();
                String publicationTime = publicationTimeField.getText();
                int price = Integer.parseInt(priceField.getText());

                // create a new book object with the values
                Book book = new Book(loginID, name, author, classCode, publicationUnit, publicationTime, price);

                // add the book object to the list
                manager.update(book);

                // clear the text fields
                loginIDField.clear();
                nameField.clear();
                authorField.clear();
                classCodeField.clear();
                publicationUnitField.clear();
                publicationTimeField.clear();
                priceField.clear();
            });
            retButton.setOnAction(event ->
                    primaryStage.setScene(new Scene(menuButton(primaryStage),500,300)));
            // add the nodes to the gridpane
            gridPane.getChildren().addAll(loginIDLabel, nameLabel, authorLabel, classCodeLabel, publicationUnitLabel, publicationTimeLabel, priceLabel, loginIDField, nameField, authorField, classCodeField, publicationUnitField, publicationTimeField, priceField, updateButton,retButton);

            // set the gridpane style
            gridPane.setStyle("-fx-background-color: lightblue;");
        return gridPane;
        }
}

